package org.yellow.backend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yellow.backend.mapper.medicineMapper;
import org.yellow.backend.pojo.medicine;

import java.util.List;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@Service
@SuppressWarnings({"all"})
public class medicineService {
    @Autowired
    medicineMapper mapper;

    /**
     * 根据id查询对应药品
     * @param id
     * @return
     */
    public medicine selectMedicineById(int id){
        return mapper.selectById(id);
    }

    /**
     * 更新库存量
     * @param volume
     * @return
     */
    public boolean decreaseStock(int volume,String medicineName){
        return mapper.decreaseStock(volume,medicineName);

    }

    /**
     * 查看药品库存量
     * @param name
     * @return
     */
    public Long selectStock(String name){
        QueryWrapper<medicine> wrapper = new QueryWrapper<>();
        wrapper.eq("medicine_name",name);
        return mapper.selectOne(wrapper).getStockQuantity();
    }

    /**
     * 查询所有药品信息
     * @return
     */
    public List<medicine> getAll(){
        return mapper.selectList(null);
    }
}
